package com.university.evaluation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.university.evaluation.entity.ScoreRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 加分记录Mapper
 */
@Mapper
public interface ScoreRecordMapper extends BaseMapper<ScoreRecord> {

    /**
     * 根据用户ID查询加分记录
     */
    @Select("SELECT * FROM t_score_record WHERE user_id = #{userId} ORDER BY submit_time DESC")
    List<ScoreRecord> findByUserId(@Param("userId") String userId);

    /**
     * 根据状态查询加分记录
     */
    @Select("SELECT * FROM t_score_record WHERE status = #{status} ORDER BY submit_time ASC")
    List<ScoreRecord> findByStatus(@Param("status") String status);

    /**
     * 根据用户ID和状态查询加分记录
     */
    @Select("SELECT * FROM t_score_record WHERE user_id = #{userId} AND status = #{status}")
    List<ScoreRecord> findByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);

    /**
     * 查询待班委审核的记录（按学院分组）
     */
    @Select("SELECT sr.* FROM t_score_record sr " +
            "JOIN t_sys_user su ON sr.user_id = su.user_id " +
            "WHERE sr.status = 'PENDING_MON' AND su.college_id = #{collegeId} " +
            "ORDER BY sr.submit_time ASC")
    List<ScoreRecord> findPendingMonitorRecordsByCollege(@Param("collegeId") String collegeId);

    /**
     * 查询待辅导员审核的记录（按学院分组）
     */
    @Select("SELECT sr.* FROM t_score_record sr " +
            "JOIN t_sys_user su ON sr.user_id = su.user_id " +
            "WHERE sr.status = 'PENDING_TCH' AND su.college_id = #{collegeId} " +
            "ORDER BY sr.submit_time ASC")
    List<ScoreRecord> findPendingTeacherRecordsByCollege(@Param("collegeId") String collegeId);
}
